﻿using Factory.WarehouseManagement.WarehouseSettings;
using Factory.WarehouseManagement.WarehouseSettings.DTO;
using Microsoft.AspNetCore.Mvc;

namespace Factory.Web.Controllers.WarehouseManagement
{
    public class BinSetController : Controller
    {
        private readonly IBinSetAppService _binSetService;

        public BinSetController(IBinSetAppService binSetService)
        {
            _binSetService = binSetService;
        }
        public IActionResult BinSetIndex(string areaCode)
        {
            ViewBag.AreaCode = areaCode;
            return View();
        }

       
        [HttpGet]
        /// <summary>
        /// 获取数据
        /// </summary>

        /// <returns></returns>
        public JsonResult GetBinSetList(string? binSetName, string areaCode, int page, int limit)
        {
            var arealist = _binSetService.GetListAsync(binSetName, areaCode, page, limit);
            return Json(new { data = arealist.Result, code = 0 });
        }

        public IActionResult BinSetAddIndex()
        {
            return View();
        }

        [HttpPost]
        public JsonResult AddBinSet(BinSet input)
        {
            var arealist = _binSetService.CreateAsync(input);
            return Json(new { code = arealist, msg = "添加成功" });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回对应数据</returns>
        [HttpPost]
        public JsonResult BinSetDelete(int id)
        {
            var arealist = _binSetService.DeleteAsync(id);
            return Json(new { code = arealist, msg = "删除成功" });
        }

        public ActionResult BinSetUpdateIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }

        [HttpGet]
        public JsonResult GetBinSetById(int id)
        {
            var arealist = _binSetService.GetBinSetById(id);
            return Json(new { data = arealist, code = 0 });
        }

        [HttpPost]
        public JsonResult UpdateBinSet(BinSetDTO input)
        {
            var arealist = _binSetService.UpdateAsync(input);
            return Json(new { code = true, data = arealist });
        }
    }
}
